package util;

import bean.OrderItem;

import java.util.ArrayList;
import java.util.List;

public class Item {
    private int pid;
    private int iid;
    private String pname;
    private int number;
    private float pprice;

    public int getIid() {
        return iid;
    }

    public void setIid(int iid) {
        this.iid = iid;
    }

    @Override
    public String toString() {
        return "Item{" +
                "pid=" + pid +
                ", pname='" + pname + '\'' +
                ", number=" + number +
                ", pprice=" + pprice +
                '}';
    }

    public static List<Item> list(List<OrderItem> orderItems)
    {
        List<Item> items = new ArrayList<>();
        for (OrderItem orderItem:
             orderItems)
        {
            int pid = orderItem.getProduct().getId();
            int iid = orderItem.getProduct().getFirstProductImage().getId();
            String pname = orderItem.getProduct().getName();
            int number = orderItem.getNumber();
            float pprice = orderItem.getProduct().getPromotePrice();
            Item item = new Item();
            item.setPid(pid);
            item.setIid(iid);
            item.setNumber(number);
            item.setPname(pname);
            item.setPprice(pprice);
            items.add(item);
        }
        return items;
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public float getPprice() {
        return pprice;
    }

    public void setPprice(float pprice) {
        this.pprice = pprice;
    }
}
